package com.wsz.eduservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wsz.commonutils.JwtUtils;
import com.wsz.commonutils.R;
import com.wsz.eduservice.client.UcenterClient;
import com.wsz.eduservice.pojo.Comment;
import com.wsz.eduservice.pojo.member.Member;
import com.wsz.eduservice.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags = "评论管理")
@RestController
@RequestMapping("/eduservice/comment")
public class EduCommentController {

    @Autowired
    private CommentService commentService;

    @Autowired
    UcenterClient ucenterClient;

    @ApiOperation("分页查询所有评论")
    @GetMapping("/getComment/{page}/{limit}")
    public R getCommont(@PathVariable long page,
                        @PathVariable long limit,
                        @RequestParam String courseId){

        Page<Comment> page1 = new Page<>(page,limit);
        Map<String,Object> map = commentService.getCommentPage(page1,courseId);

        return R.ok().data("map",map);
    }


//    @ApiOperation("添加评论")
//    @PostMapping("/addComment")
//    public R addComment(@RequestBody Comment comment,
//                        HttpServletRequest request){
//
//        String member = JwtUtils.getMemberIdByJwtToken(request);
//
//        if(StringUtils.isNotBlank(member)){
//            return R.error().code(20001).message("请登录后在评论");
//        }
//
//        R memberInfo = ucenterClient.getMemberInfoOrder(request);
//
//        Map<String, Object> data = memberInfo.getData();
//
//        Member userInfo = (Member)data.get("userInfo");
//
//        String nickname = userInfo.getNickname();
//        String avatar = userInfo.getAvatar();
//
//        comment.setNickname(nickname);
//        comment.setAvatar(avatar);
//        comment.setMemberId(member);
//
//        commentService.save(comment);
//
//        return R.ok();
//    }
}
